<?php
namespace app\screenshot\home;
use app\common\controller\Common;
use think\Exception;
use think\DB;
class Index extends Common
{   
    public function index()
    {
       echo 'hello';
    }
   public function lunbo()
    {
        $data_list = Db::name('screenshot_lunbo')->order('shunxu desc')->where("status = '1'")->select();
        return json($data_list);
    }
    public function more()
    {
        $data_list = Db::name('screenshot_more')->order('shunxu desc')->where("status = '1'")->select();
        return json($data_list);
    }
    public function getPrice()
    {   
        $name = input("name");
  
        $data = json_decode($this->http("https://api.coinmarketcap.com/v2/listings/"));

        foreach ($data->data as $key => $value) {
            # code...
            if($name == $value->symbol) {
                echo round($value->quotes->USD->price * 6.7769,2);
            }
        }
        //return $this->fetch();
    }
    function http($url, $data = array(), $timeout = 10){
        if($url == "" || $timeout <= 0){
            return false;
        }
        if($data != array()) {
            $url = $url . '?' . http_build_query($data);
        }
        
        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, false);
        curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout);
        curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($con, CURLOPT_SSL_VERIFYHOST, false);
        return curl_exec($con);
    }
}